import yaml
import os
import git

class MetaCheck(object):
    
    def __init__(self, meta_dir) -> None:
        self.meta_dir = meta_dir

    def exec(self, src_dir):

        with open(self.meta_dir, 'r') as f:
            data = yaml.load(f, yaml.Loader)

        metaList = data["metalist"]
        for item in metaList:
            if os.path.exists(os.path.join(src_dir, item["path"])):
                try:
                    repo = git.Repo(os.path.join(src_dir, item["path"]))
                    repo.git.checkout(item['branch'])
                except:
                    continue
    